{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
      "0        1  2011-01-01       1   0     1        0        6           0   \n",
      "1        2  2011-01-02       1   0     1        0        0           0   \n",
      "2        3  2011-01-03       1   0     1        0        1           1   \n",
      "3        4  2011-01-04       1   0     1        0        2           1   \n",
      "4        5  2011-01-05       1   0     1        0        3           1   \n",
      "\n",
      "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
      "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
      "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
      "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
      "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
      "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
      "\n",
      "    cnt  \n",
      "0   985  \n",
      "1   801  \n",
      "2  1349  \n",
      "3  1562  \n",
      "4  1600  \n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 16 columns):\n",
      "instant       731 non-null int64\n",
      "dteday        731 non-null object\n",
      "season        731 non-null int64\n",
      "yr            731 non-null int64\n",
      "mnth          731 non-null int64\n",
      "holiday       731 non-null int64\n",
      "weekday       731 non-null int64\n",
      "workingday    731 non-null int64\n",
      "weathersit    731 non-null int64\n",
      "temp          731 non-null float64\n",
      "atemp         731 non-null float64\n",
      "hum           731 non-null float64\n",
      "windspeed     731 non-null float64\n",
      "casual        731 non-null int64\n",
      "registered    731 non-null int64\n",
      "cnt           731 non-null int64\n",
      "dtypes: float64(4), int64(11), object(1)\n",
      "memory usage: 91.5+ KB\n",
      "None\n",
      "(731, 16)\n",
      "          instant      season          yr        mnth     holiday     weekday  \\\n",
      "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
      "mean   366.000000    2.496580    0.500684    6.519836    0.028728    2.997264   \n",
      "std    211.165812    1.110807    0.500342    3.451913    0.167155    2.004787   \n",
      "min      1.000000    1.000000    0.000000    1.000000    0.000000    0.000000   \n",
      "25%    183.500000    2.000000    0.000000    4.000000    0.000000    1.000000   \n",
      "50%    366.000000    3.000000    1.000000    7.000000    0.000000    3.000000   \n",
      "75%    548.500000    3.000000    1.000000   10.000000    0.000000    5.000000   \n",
      "max    731.000000    4.000000    1.000000   12.000000    1.000000    6.000000   \n",
      "\n",
      "       workingday  weathersit        temp       atemp         hum   windspeed  \\\n",
      "count  731.000000  731.000000  731.000000  731.000000  731.000000  731.000000   \n",
      "mean     0.683995    1.395349    0.495385    0.474354    0.627894    0.190486   \n",
      "std      0.465233    0.544894    0.183051    0.162961    0.142429    0.077498   \n",
      "min      0.000000    1.000000    0.059130    0.079070    0.000000    0.022392   \n",
      "25%      0.000000    1.000000    0.337083    0.337842    0.520000    0.134950   \n",
      "50%      1.000000    1.000000    0.498333    0.486733    0.626667    0.180975   \n",
      "75%      1.000000    2.000000    0.655417    0.608602    0.730209    0.233214   \n",
      "max      1.000000    3.000000    0.861667    0.840896    0.972500    0.507463   \n",
      "\n",
      "            casual   registered          cnt  \n",
      "count   731.000000   731.000000   731.000000  \n",
      "mean    848.176471  3656.172367  4504.348837  \n",
      "std     686.622488  1560.256377  1937.211452  \n",
      "min       2.000000    20.000000    22.000000  \n",
      "25%     315.500000  2497.000000  3152.000000  \n",
      "50%     713.000000  3662.000000  4548.000000  \n",
      "75%    1096.000000  4776.500000  5956.000000  \n",
      "max    3410.000000  6946.000000  8714.000000  \n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"day.csv\")\n",
    "print(df.head())\n",
    "print(df.info())\n",
    "print(df.shape)\n",
    "print(df.describe())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0       985\n",
      "1       801\n",
      "2      1349\n",
      "3      1562\n",
      "4      1600\n",
      "5      1606\n",
      "6      1510\n",
      "7       959\n",
      "8       822\n",
      "9      1321\n",
      "10     1263\n",
      "11     1162\n",
      "12     1406\n",
      "13     1421\n",
      "14     1248\n",
      "15     1204\n",
      "16     1000\n",
      "17      683\n",
      "18     1650\n",
      "19     1927\n",
      "20     1543\n",
      "21      981\n",
      "22      986\n",
      "23     1416\n",
      "24     1985\n",
      "25      506\n",
      "26      431\n",
      "27     1167\n",
      "28     1098\n",
      "29     1096\n",
      "       ... \n",
      "701    4649\n",
      "702    6234\n",
      "703    6606\n",
      "704    5729\n",
      "705    5375\n",
      "706    5008\n",
      "707    5582\n",
      "708    3228\n",
      "709    5170\n",
      "710    5501\n",
      "711    5319\n",
      "712    5532\n",
      "713    5611\n",
      "714    5047\n",
      "715    3786\n",
      "716    4585\n",
      "717    5557\n",
      "718    5267\n",
      "719    4128\n",
      "720    3623\n",
      "721    1749\n",
      "722    1787\n",
      "723     920\n",
      "724    1013\n",
      "725     441\n",
      "726    2114\n",
      "727    3095\n",
      "728    1341\n",
      "729    1796\n",
      "730    2729\n",
      "Name: cnt, Length: 731, dtype: int64\n",
      "     instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
      "0          1  2011-01-01       1   0     1        0        6           0   \n",
      "1          2  2011-01-02       1   0     1        0        0           0   \n",
      "2          3  2011-01-03       1   0     1        0        1           1   \n",
      "3          4  2011-01-04       1   0     1        0        2           1   \n",
      "4          5  2011-01-05       1   0     1        0        3           1   \n",
      "5          6  2011-01-06       1   0     1        0        4           1   \n",
      "6          7  2011-01-07       1   0     1        0        5           1   \n",
      "7          8  2011-01-08       1   0     1        0        6           0   \n",
      "8          9  2011-01-09       1   0     1        0        0           0   \n",
      "9         10  2011-01-10       1   0     1        0        1           1   \n",
      "10        11  2011-01-11       1   0     1        0        2           1   \n",
      "11        12  2011-01-12       1   0     1        0        3           1   \n",
      "12        13  2011-01-13       1   0     1        0        4           1   \n",
      "13        14  2011-01-14       1   0     1        0        5           1   \n",
      "14        15  2011-01-15       1   0     1        0        6           0   \n",
      "15        16  2011-01-16       1   0     1        0        0           0   \n",
      "16        17  2011-01-17       1   0     1        1        1           0   \n",
      "17        18  2011-01-18       1   0     1        0        2           1   \n",
      "18        19  2011-01-19       1   0     1        0        3           1   \n",
      "19        20  2011-01-20       1   0     1        0        4           1   \n",
      "20        21  2011-01-21       1   0     1        0        5           1   \n",
      "21        22  2011-01-22       1   0     1        0        6           0   \n",
      "22        23  2011-01-23       1   0     1        0        0           0   \n",
      "23        24  2011-01-24       1   0     1        0        1           1   \n",
      "24        25  2011-01-25       1   0     1        0        2           1   \n",
      "25        26  2011-01-26       1   0     1        0        3           1   \n",
      "26        27  2011-01-27       1   0     1        0        4           1   \n",
      "27        28  2011-01-28       1   0     1        0        5           1   \n",
      "28        29  2011-01-29       1   0     1        0        6           0   \n",
      "29        30  2011-01-30       1   0     1        0        0           0   \n",
      "..       ...         ...     ...  ..   ...      ...      ...         ...   \n",
      "701      702  2012-12-02       4   1    12        0        0           0   \n",
      "702      703  2012-12-03       4   1    12        0        1           1   \n",
      "703      704  2012-12-04       4   1    12        0        2           1   \n",
      "704      705  2012-12-05       4   1    12        0        3           1   \n",
      "705      706  2012-12-06       4   1    12        0        4           1   \n",
      "706      707  2012-12-07       4   1    12        0        5           1   \n",
      "707      708  2012-12-08       4   1    12        0        6           0   \n",
      "708      709  2012-12-09       4   1    12        0        0           0   \n",
      "709      710  2012-12-10       4   1    12        0        1           1   \n",
      "710      711  2012-12-11       4   1    12        0        2           1   \n",
      "711      712  2012-12-12       4   1    12        0        3           1   \n",
      "712      713  2012-12-13       4   1    12        0        4           1   \n",
      "713      714  2012-12-14       4   1    12        0        5           1   \n",
      "714      715  2012-12-15       4   1    12        0        6           0   \n",
      "715      716  2012-12-16       4   1    12        0        0           0   \n",
      "716      717  2012-12-17       4   1    12        0        1           1   \n",
      "717      718  2012-12-18       4   1    12        0        2           1   \n",
      "718      719  2012-12-19       4   1    12        0        3           1   \n",
      "719      720  2012-12-20       4   1    12        0        4           1   \n",
      "720      721  2012-12-21       1   1    12        0        5           1   \n",
      "721      722  2012-12-22       1   1    12        0        6           0   \n",
      "722      723  2012-12-23       1   1    12        0        0           0   \n",
      "723      724  2012-12-24       1   1    12        0        1           1   \n",
      "724      725  2012-12-25       1   1    12        1        2           0   \n",
      "725      726  2012-12-26       1   1    12        0        3           1   \n",
      "726      727  2012-12-27       1   1    12        0        4           1   \n",
      "727      728  2012-12-28       1   1    12        0        5           1   \n",
      "728      729  2012-12-29       1   1    12        0        6           0   \n",
      "729      730  2012-12-30       1   1    12        0        0           0   \n",
      "730      731  2012-12-31       1   1    12        0        1           1   \n",
      "\n",
      "     weathersit      temp     atemp       hum  windspeed  \n",
      "0             2  0.344167  0.363625  0.805833   0.160446  \n",
      "1             2  0.363478  0.353739  0.696087   0.248539  \n",
      "2             1  0.196364  0.189405  0.437273   0.248309  \n",
      "3             1  0.200000  0.212122  0.590435   0.160296  \n",
      "4             1  0.226957  0.229270  0.436957   0.186900  \n",
      "5             1  0.204348  0.233209  0.518261   0.089565  \n",
      "6             2  0.196522  0.208839  0.498696   0.168726  \n",
      "7             2  0.165000  0.162254  0.535833   0.266804  \n",
      "8             1  0.138333  0.116175  0.434167   0.361950  \n",
      "9             1  0.150833  0.150888  0.482917   0.223267  \n",
      "10            2  0.169091  0.191464  0.686364   0.122132  \n",
      "11            1  0.172727  0.160473  0.599545   0.304627  \n",
      "12            1  0.165000  0.150883  0.470417   0.301000  \n",
      "13            1  0.160870  0.188413  0.537826   0.126548  \n",
      "14            2  0.233333  0.248112  0.498750   0.157963  \n",
      "15            1  0.231667  0.234217  0.483750   0.188433  \n",
      "16            2  0.175833  0.176771  0.537500   0.194017  \n",
      "17            2  0.216667  0.232333  0.861667   0.146775  \n",
      "18            2  0.292174  0.298422  0.741739   0.208317  \n",
      "19            2  0.261667  0.255050  0.538333   0.195904  \n",
      "20            1  0.177500  0.157833  0.457083   0.353242  \n",
      "21            1  0.059130  0.079070  0.400000   0.171970  \n",
      "22            1  0.096522  0.098839  0.436522   0.246600  \n",
      "23            1  0.097391  0.117930  0.491739   0.158330  \n",
      "24            2  0.223478  0.234526  0.616957   0.129796  \n",
      "25            3  0.217500  0.203600  0.862500   0.293850  \n",
      "26            1  0.195000  0.219700  0.687500   0.113837  \n",
      "27            2  0.203478  0.223317  0.793043   0.123300  \n",
      "28            1  0.196522  0.212126  0.651739   0.145365  \n",
      "29            1  0.216522  0.250322  0.722174   0.073983  \n",
      "..          ...       ...       ...       ...        ...  \n",
      "701           2  0.347500  0.359208  0.823333   0.124379  \n",
      "702           1  0.452500  0.455796  0.767500   0.082721  \n",
      "703           1  0.475833  0.469054  0.733750   0.174129  \n",
      "704           1  0.438333  0.428012  0.485000   0.324021  \n",
      "705           1  0.255833  0.258204  0.508750   0.174754  \n",
      "706           2  0.320833  0.321958  0.764167   0.130600  \n",
      "707           2  0.381667  0.389508  0.911250   0.101379  \n",
      "708           2  0.384167  0.390146  0.905417   0.157975  \n",
      "709           2  0.435833  0.435575  0.925000   0.190308  \n",
      "710           2  0.353333  0.338363  0.596667   0.296037  \n",
      "711           2  0.297500  0.297338  0.538333   0.162937  \n",
      "712           1  0.295833  0.294188  0.485833   0.174129  \n",
      "713           1  0.281667  0.294192  0.642917   0.131229  \n",
      "714           1  0.324167  0.338383  0.650417   0.106350  \n",
      "715           2  0.362500  0.369938  0.838750   0.100742  \n",
      "716           2  0.393333  0.401500  0.907083   0.098258  \n",
      "717           1  0.410833  0.409708  0.666250   0.221404  \n",
      "718           1  0.332500  0.342162  0.625417   0.184092  \n",
      "719           2  0.330000  0.335217  0.667917   0.132463  \n",
      "720           2  0.326667  0.301767  0.556667   0.374383  \n",
      "721           1  0.265833  0.236113  0.441250   0.407346  \n",
      "722           1  0.245833  0.259471  0.515417   0.133083  \n",
      "723           2  0.231304  0.258900  0.791304   0.077230  \n",
      "724           2  0.291304  0.294465  0.734783   0.168726  \n",
      "725           3  0.243333  0.220333  0.823333   0.316546  \n",
      "726           2  0.254167  0.226642  0.652917   0.350133  \n",
      "727           2  0.253333  0.255046  0.590000   0.155471  \n",
      "728           2  0.253333  0.242400  0.752917   0.124383  \n",
      "729           1  0.255833  0.231700  0.483333   0.350754  \n",
      "730           2  0.215833  0.223487  0.577500   0.154846  \n",
      "\n",
      "[731 rows x 13 columns]\n"
     ]
    }
   ],
   "source": [
    "#数据分离\n",
    "y = df['cnt']\n",
    "X = df.drop('casual',axis = 1)\n",
    "X = X.drop('registered',axis =1)\n",
    "X = X.drop('cnt',axis =1)\n",
    "log_y = np.log1p(y)\n",
    "print(y)\n",
    "print(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   season_1  season_2  season_3  season_4\n",
      "0         1         0         0         0\n",
      "1         1         0         0         0\n",
      "2         1         0         0         0\n",
      "3         1         0         0         0\n",
      "4         1         0         0         0\n"
     ]
    }
   ],
   "source": [
    "#离散型特征编码\n",
    "X[\"season\"].astype(\"object\")\n",
    "X1_cat = X[\"season\"]\n",
    "X1_cat = pd.get_dummies(X1_cat,prefix = \"season\")\n",
    "X = X.drop(\"season\",axis = 1)\n",
    "print(X1_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   yr_0  yr_1\n",
      "0     1     0\n",
      "1     1     0\n",
      "2     1     0\n",
      "3     1     0\n",
      "4     1     0\n"
     ]
    }
   ],
   "source": [
    "X[\"yr\"].astype(\"object\")\n",
    "X2_cat = X[\"yr\"]\n",
    "X2_cat = pd.get_dummies(X2_cat,prefix = \"yr\")\n",
    "X = X.drop(\"yr\",axis = 1)\n",
    "print(X2_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   mnth_1  mnth_2  mnth_3  mnth_4  mnth_5  mnth_6  mnth_7  mnth_8  mnth_9  \\\n",
      "0       1       0       0       0       0       0       0       0       0   \n",
      "1       1       0       0       0       0       0       0       0       0   \n",
      "2       1       0       0       0       0       0       0       0       0   \n",
      "3       1       0       0       0       0       0       0       0       0   \n",
      "4       1       0       0       0       0       0       0       0       0   \n",
      "\n",
      "   mnth_10  mnth_11  mnth_12  \n",
      "0        0        0        0  \n",
      "1        0        0        0  \n",
      "2        0        0        0  \n",
      "3        0        0        0  \n",
      "4        0        0        0  \n"
     ]
    }
   ],
   "source": [
    "X[\"mnth\"].astype(\"object\")\n",
    "X3_cat = X[\"mnth\"]\n",
    "X3_cat = pd.get_dummies(X3_cat,prefix = \"mnth\")\n",
    "X = X.drop(\"mnth\",axis = 1)\n",
    "print(X3_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   holiday_0  holiday_1\n",
      "0          1          0\n",
      "1          1          0\n",
      "2          1          0\n",
      "3          1          0\n",
      "4          1          0\n"
     ]
    }
   ],
   "source": [
    "X[\"holiday\"].astype(\"object\")\n",
    "X4_cat = X[\"holiday\"]\n",
    "X4_cat = pd.get_dummies(X4_cat,prefix = \"holiday\")\n",
    "X = X.drop(\"holiday\",axis = 1)\n",
    "print(X4_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   weekday_0  weekday_1  weekday_2  weekday_3  weekday_4  weekday_5  weekday_6\n",
      "0          0          0          0          0          0          0          1\n",
      "1          1          0          0          0          0          0          0\n",
      "2          0          1          0          0          0          0          0\n",
      "3          0          0          1          0          0          0          0\n",
      "4          0          0          0          1          0          0          0\n"
     ]
    }
   ],
   "source": [
    "X[\"weekday\"].astype(\"object\")\n",
    "X5_cat = X[\"weekday\"]\n",
    "X5_cat = pd.get_dummies(X5_cat,prefix = \"weekday\")\n",
    "X = X.drop(\"weekday\",axis = 1)\n",
    "print(X5_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   workingday_0  workingday_1\n",
      "0             1             0\n",
      "1             1             0\n",
      "2             0             1\n",
      "3             0             1\n",
      "4             0             1\n"
     ]
    }
   ],
   "source": [
    "X[\"workingday\"].astype(\"object\")\n",
    "X6_cat = X[\"workingday\"]\n",
    "X6_cat = pd.get_dummies(X6_cat,prefix = \"workingday\")\n",
    "X = X.drop(\"workingday\",axis = 1)\n",
    "print(X6_cat.head())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   weathersit_1  weathersit_2  weathersit_3\n",
      "0             0             1             0\n",
      "1             0             1             0\n",
      "2             1             0             0\n",
      "3             1             0             0\n",
      "4             1             0             0\n"
     ]
    }
   ],
   "source": [
    "X[\"weathersit\"].astype(\"object\")\n",
    "X7_cat = X[\"weathersit\"]\n",
    "X7_cat = pd.get_dummies(X7_cat,prefix = \"weathersit\")\n",
    "X = X.drop(\"weathersit\",axis = 1)\n",
    "print(X7_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "#特征名称\n",
    "feat_names = X.columns\n",
    "#数值型特征预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   instant      dteday      temp     atemp       hum  windspeed  season_1  \\\n",
      "0        1  2011-01-01  0.344167  0.363625  0.805833   0.160446         1   \n",
      "1        2  2011-01-02  0.363478  0.353739  0.696087   0.248539         1   \n",
      "2        3  2011-01-03  0.196364  0.189405  0.437273   0.248309         1   \n",
      "3        4  2011-01-04  0.200000  0.212122  0.590435   0.160296         1   \n",
      "4        5  2011-01-05  0.226957  0.229270  0.436957   0.186900         1   \n",
      "\n",
      "   season_2  season_3  season_4    ...     weekday_4  weekday_5  weekday_6  \\\n",
      "0         0         0         0    ...             0          0          1   \n",
      "1         0         0         0    ...             0          0          0   \n",
      "2         0         0         0    ...             0          0          0   \n",
      "3         0         0         0    ...             0          0          0   \n",
      "4         0         0         0    ...             0          0          0   \n",
      "\n",
      "   workingday_0  workingday_1  weathersit_1  weathersit_2  weathersit_3   cnt  \\\n",
      "0             1             0             0             1             0   985   \n",
      "1             1             0             0             1             0   801   \n",
      "2             0             1             1             0             0  1349   \n",
      "3             0             1             1             0             0  1562   \n",
      "4             0             1             1             0             0  1600   \n",
      "\n",
      "    log_cnt  \n",
      "0  6.893656  \n",
      "1  6.687109  \n",
      "2  7.207860  \n",
      "3  7.354362  \n",
      "4  7.378384  \n",
      "\n",
      "[5 rows x 40 columns]\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 40 columns):\n",
      "instant         731 non-null int64\n",
      "dteday          731 non-null object\n",
      "temp            731 non-null float64\n",
      "atemp           731 non-null float64\n",
      "hum             731 non-null float64\n",
      "windspeed       731 non-null float64\n",
      "season_1        731 non-null uint8\n",
      "season_2        731 non-null uint8\n",
      "season_3        731 non-null uint8\n",
      "season_4        731 non-null uint8\n",
      "yr_0            731 non-null uint8\n",
      "yr_1            731 non-null uint8\n",
      "mnth_1          731 non-null uint8\n",
      "mnth_2          731 non-null uint8\n",
      "mnth_3          731 non-null uint8\n",
      "mnth_4          731 non-null uint8\n",
      "mnth_5          731 non-null uint8\n",
      "mnth_6          731 non-null uint8\n",
      "mnth_7          731 non-null uint8\n",
      "mnth_8          731 non-null uint8\n",
      "mnth_9          731 non-null uint8\n",
      "mnth_10         731 non-null uint8\n",
      "mnth_11         731 non-null uint8\n",
      "mnth_12         731 non-null uint8\n",
      "holiday_0       731 non-null uint8\n",
      "holiday_1       731 non-null uint8\n",
      "weekday_0       731 non-null uint8\n",
      "weekday_1       731 non-null uint8\n",
      "weekday_2       731 non-null uint8\n",
      "weekday_3       731 non-null uint8\n",
      "weekday_4       731 non-null uint8\n",
      "weekday_5       731 non-null uint8\n",
      "weekday_6       731 non-null uint8\n",
      "workingday_0    731 non-null uint8\n",
      "workingday_1    731 non-null uint8\n",
      "weathersit_1    731 non-null uint8\n",
      "weathersit_2    731 non-null uint8\n",
      "weathersit_3    731 non-null uint8\n",
      "cnt             731 non-null int64\n",
      "log_cnt         731 non-null float64\n",
      "dtypes: float64(5), int64(2), object(1), uint8(32)\n",
      "memory usage: 68.6+ KB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "#保存工程结果到文件\n",
    "fe_data = pd.DataFrame(data = X, columns = feat_names, index = df.index)\n",
    "fe_data = pd.concat([fe_data,X1_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X2_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X3_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X4_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X5_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X6_cat],axis = 1,ignore_index = False)\n",
    "fe_data = pd.concat([fe_data,X7_cat],axis = 1,ignore_index = False)\n",
    "\n",
    "fe_data[\"cnt\"] = y\n",
    "fe_data[\"log_cnt\"] = log_y\n",
    "\n",
    "fe_data.to_csv('sharingbike.csv',index = False)\n",
    "\n",
    "print(fe_data.head())\n",
    "print(fe_data.info())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
